package com.njtoyo.taxi.admin.service.business.operation_rule.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njtoyo.taxi.admin.mapper.master.entity.DriverRegionServiceArrangement;
import com.njtoyo.taxi.admin.mapper.master.entity.SimpleCallInfoServiceFeeRule;
import com.njtoyo.taxi.admin.mapper.master.mapper.SimpleCallInfoServiceFeeRuleMapper;
import com.njtoyo.taxi.admin.rest.presenter.business.operation_rule.SimpleCallInfoServiceFeeRulePresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.SimpleCallServiceRuleAddUpdateWrapper;
import com.njtoyo.taxi.admin.service.business.operation_rule.SimpleCallInfoServiceFeeRuleService;
import com.taxi.entity.common.RestResult;
import org.springframework.stereotype.Service;


@Service
public class SimpleCallInfoServiceFeeRuleServiceImpl extends ServiceImpl<SimpleCallInfoServiceFeeRuleMapper, SimpleCallInfoServiceFeeRule> implements SimpleCallInfoServiceFeeRuleService {
    @Override
    public IPage<SimpleCallInfoServiceFeeRulePresenter> getPage(Integer current, Integer size, String driverRegionName) {
        Page<SimpleCallInfoServiceFeeRulePresenter> page = new Page<>(current, size);
        IPage<SimpleCallInfoServiceFeeRulePresenter> pages = baseMapper.getPage(page, driverRegionName);
        return pages;
    }

    @Override
    public RestResult add(SimpleCallServiceRuleAddUpdateWrapper wrapper) {
        SimpleCallInfoServiceFeeRule rule = new SimpleCallInfoServiceFeeRule();
        rule.setDriverRegionId(wrapper.getDriverRegionId());
        rule.setFixedAmount(wrapper.getFixedAmount());
        rule.setIsActive(false);
        baseMapper.insert(rule);
        return RestResult.success();
    }

    @Override
    public RestResult update(SimpleCallServiceRuleAddUpdateWrapper wrapper) {
        SimpleCallInfoServiceFeeRule rule = new SimpleCallInfoServiceFeeRule();
        rule.setId(wrapper.getId());
        rule.setDriverRegionId(wrapper.getDriverRegionId());
        rule.setFixedAmount(wrapper.getFixedAmount());
        baseMapper.updateById(rule);
        return RestResult.success();
    }

    @Override
    public RestResult getInfoById(Long id) {
        return RestResult.success(baseMapper.selectById(id));
    }

    @Override
    public RestResult deleteById(Long id) {
        return RestResult.success(baseMapper.deleteById(id));
    }

    @Override
    public RestResult updateActive(SimpleCallServiceRuleAddUpdateWrapper wrapper) {
        SimpleCallInfoServiceFeeRule rule = new SimpleCallInfoServiceFeeRule();
        rule.setId(wrapper.getId());
        rule.setIsActive(wrapper.getIsActive());
        baseMapper.updateById(rule);
        return RestResult.success();
    }
}
